// xc_lshop/shop/order/task/info.js
// var actbill = require('../../model/order_task')
var actbill = require('../../model/order_bill')

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    xcmodel:null,
    show:false,
    nowtime:Date.now()

  },
   //邀请好友
   invite() {
    this.selectComponent("#widgetsshare").showSharefunc();
  },
  xcloaddata: function (options, config) {
    var that = this;

    if (config.task){
      this.setData({
        taskname: config.task.taskname
      })
    }
  },
  getmodel: function (id,uid) {
    var that = this;
    actbill.getmodel(id).then(res => {
      if (res.status == 1) {
        var obj = res.obj;
        if(obj.uid!=uid){
          that.pageback()
        }
        var nowtime=Date.now()
        if(obj.taskinfo && obj.taskinfo['taskstatus']==1 && (obj.taskinfo.validityend * 1000 - nowtime) <= 0){
          obj.taskinfo['taskstatus']=-2
        }
        
        // if(obj.taskinfo.taskstatus==1 && obj.taskinfo.validityend * 1000>nowtime){
        //   // that.autoexcel();
        // }
       console.log("xcmodel")

       console.log(obj)
        that.setData({
          xcmodel: obj
        })
      
      }else{
        that.error("数据不存在",true)
      }
    })
  },
  afterlogin: function (options, config, userinfo) {
    var app = getApp()
    var that = this;
    this.setData({
      member:userinfo
    })
    if(userinfo['member_id']){
      that.getmodel(options.id,userinfo['member_id'])
    }
  },
  onpopShow(){
    this.setData({
      show:true
    })
  },
  onpopClose(){
    this.setData({
      show:false
    })
  },
  ontimeChange(e){
    this.setData({
      timeData: e.detail,
    });
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    var app = getApp()
    var xcmodel=this.data.xcmodel;
    var proinfo=xcmodel['orderinfo'][0]
    var sharetitle = proinfo['name'];
    var shareimg = proinfo['simg'];

    // if(xcmodel['customdata'] && xcmodel['customdata']['share'] && xcmodel['customdata']['share']['status']==1){
    //   sharetitle=xcmodel['customdata']['share']['name'];
    //   shareimg=xcmodel['customdata']['share']['imageUrl']
    // }else{
    //   sharetitle = this.shasretitle()
    //   shareimg = this.data.shareimg
    // }
    const sharepath = '/xc_lshop/shop/pro/proinfo?id='+proinfo['proid']+'&activityid='+proinfo['activityid']+'&shareid='+this.data.member.member_id+'&taskid='+xcmodel.taskinfo.id;
    console.log(sharetitle)
    console.log(sharepath)
    console.log(shareimg)

    return {
      title: sharetitle,
      path: sharepath,
      imageUrl: shareimg
    }
  }
})